const mongoOperation = require("../db/operation");

const collectionName = "user";

async function addUser(user) {
    const { err, result } = await mongoOperation.doCreate(collectionName, user);
    return {
        err,
        result,
        msg: err ? "添加用户失败" : "添加用户成功",
    };
}

function deleteUser(id) {}

/* 按照条件查询指定的用户 */
async function getUsers(user) {
    const { err, result } = await mongoOperation.doRetrieve(
        collectionName,
        user
    );
    return err ? [] : result;
}

/* 修改用户 */
async function updateUser(id, user) {
    const { err, result } = await mongoOperation.doUpdate(
        collectionName,id,user
    );

    return {
        err,
        result,
        msg: err ? "用户信息更新失败" : "用户信息更新成功",
    };
}

module.exports = {
    addUser,
    deleteUser,
    updateUser,
    getUsers,
    updateUser,
};
